//
//  PhotoCollectionTests.m
//  Memento 2.0
//
//  Created by Chris on 2010-07-05.
//  Copyright 2010 Christopher Maddocks. All rights reserved.
//
//  10-08-04: Update for new signature for generateMemoryWithImage:.  (C. Maddocks)
//  10-07-30: Update for new signature for generateMemoryWithImage:  (C. Maddocks)
//  10-07-21: Bump version in header to 2.0.  (C. Maddocks)

#import "PhotoCollectionTests.h"


@implementation PhotoCollectionTests
             // all code under test must be linked into the Unit Test bundle

- (void) helpAddMemoryWithId:(int)memoryId 
					imageFile:(NSString *)imageFile
					audioFile:(NSString *)audioFile
						 date:(NSDate *)date
						  lat:(double)lat
						  lng:(double)lng 
{
	Memory *memory = [[[Memory alloc] initWithDictionary:[NSDictionary dictionaryWithObjectsAndKeys:
														  [NSNumber numberWithInt:memoryId], kMemoryId,
														  imageFile, kImagePath,
														  audioFile, @"AudioPath", //kAudioPath,
														  date, kDateTime,
														  [NSNumber numberWithDouble:lat], kLatitude,
														  [NSNumber numberWithDouble:lng], kLongitude, 
														  nil]] retain];	 
	STAssertTrue( [memory memoryId], @"Memory ID did not match" );
	STAssertTrue( [[memory dateTime] isEqualToDate:date], @"DateTime did not match" );
	STAssertTrue( [memory location].latitude == lat, @"Latitude did not match" );
	STAssertTrue( [memory location].longitude == lng, @"Longitude did not match" );
	
	[memory release];	
}


- (void) testPhotoCollection {
    PhotoCollection *pc = [[PhotoCollection alloc] init];
	
	int nextMemoryId = [pc nextMemoryId];
	
	STAssertTrue( [pc count] == 0, @"Unexpected intial number of memories in photo collection" );
	
	
	[pc addMemoryWithContentsOfDictionary:[NSDictionary dictionaryWithObjectsAndKeys:
										   [NSNumber numberWithInt:4], kMemoryId,
										   @"some_image_file.png", kImagePath,
										   @"some_audio_file.png", kAudioPath,
										   [NSDate date], kDateTime,
										   [NSNumber numberWithDouble:122.88], kLatitude,
										   [NSNumber numberWithDouble:133.77], kLongitude, 
										   nil]];
	
	[pc addMemoryWithContentsOfDictionary:[NSDictionary dictionaryWithObjectsAndKeys:
										   [NSNumber numberWithInt:5], kMemoryId,
										   @"some_image_file2.png", kImagePath,
										   @"some_audio_file2.png", kAudioPath,
										   [NSDate date], kDateTime,
										   [NSNumber numberWithDouble:123.88], kLatitude,
										   [NSNumber numberWithDouble:134.77], kLongitude, 
										   nil]];
	
	[pc addMemoryWithContentsOfDictionary:[NSDictionary dictionaryWithObjectsAndKeys:
										   [NSNumber numberWithInt:6], kMemoryId,
										   @"some_image_file3.png", kImagePath,
										   @"some_audio_file3.png", kAudioPath,
										   [NSDate date], kDateTime,
										   [NSNumber numberWithDouble:124.48], kLatitude,
										   [NSNumber numberWithDouble:134.67], kLongitude, 
										   nil]];
	
	STAssertTrue( [pc count] == 3, @"Unexpected number of memories in photo collection" );
	
	
	[pc moveFirst];
	STAssertTrue( [pc currentMemory].memoryId == 4, @"Unexpected memory at first position" );
	
	[pc moveNext];
	STAssertTrue( [pc currentMemory].memoryId == 5, @"Unexpected memory at next position" );
	
	[pc moveLast];
	STAssertTrue( [pc currentMemory].memoryId == 6, @"Unexpected memory at last position" );
	
	[pc movePrev];
	STAssertTrue( [pc currentMemory].memoryId == 5, @"Unexpected memory at prev position" );
	
	
	// Test boundaries
	[pc moveFirst];
	STAssertFalse( [pc movePrev], @"Unexpected data past first position" );
	
	[pc moveLast];
	STAssertFalse( [pc moveNext], @"Unexpected data past last position" );
	
	
	// Test memory generation
	CLLocationCoordinate2D coord;
	coord.latitude = 0;
	coord.longitude = 0;
	[pc generateMemoryWithImage:nil location:coord];	
	STAssertTrue( [pc count] == 4, @"Unexpected number of memories in photo collection after generateMemory" );
	STAssertTrue( [pc nextMemoryId] == nextMemoryId+1, @"Unexpected nextMemoryId after generateMemory" );
		
	
	[pc release];
}



- (void)testFileAccess {
/* these tests currently crash Memento.  future expansion.
 NSString *plistPath = [[[NSBundle bundleForClass:[self class]] pathForResource:@"testcatalog" ofType:@"plist"] retain];
	PhotoCollection *pc = [[[PhotoCollection alloc] initWithContentsOfFile:plistPath] retain];
	[plistPath release];
	
	STAssertTrue( [pc nextMemoryId] == 4, [NSString stringWithFormat:@"Unexpected nextMemoryId, actual %d", [pc nextMemoryId]] );

	[pc moveFirst];
	STAssertTrue( [pc currentMemory].memoryId == 1, @"Unexpected memory at first position" );

	[pc moveLast];
	STAssertTrue( [pc currentMemory].memoryId == 3, @"Unexpected memory at last position" );

	STAssertTrue( [pc count] == 3, @"Unexpected number of memories" );
	
	[pc release];
*/
}



@end
